package com.itbaizhan.controller;

/**
 * @author spf
 * @date 2024/3/4
 * @time 15:33
 */

import com.itbaizhan.pojo.Item;
import com.itbaizhan.pojo.Order;
import com.itbaizhan.result.BaseResult;
import com.itbaizhan.service.DetailService;
import com.itbaizhan.service.OrderServiceOpenFeign;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品详情控制器
 */
@RestController
@RequestMapping("/detail")
public class DetailController {

    @Autowired
    private DetailService detailService;
    @Autowired(required = false)
    private OrderServiceOpenFeign orderServiceOpenFeign;

    /**
     * 根据id查询商品
     * @param id 商品id
     * @return 执行结果
     */
    @GetMapping("/findById")
    public BaseResult<Item> findById(@RequestParam("id") String id){
        if (StringUtil.isNullOrEmpty(id)){
            return null;
        }
        Item item = detailService.getDetails(id);
        return BaseResult.ok(item);
    }

    @GetMapping("/testDetails")
    public BaseResult testDetails(){
        ArrayList<String> list = new
                ArrayList<>();
        list.add("65e57cd895c7f93af5028c26");
        list.add("65e57cd895c7f93af5028c27");
        list.add("65e57cd895c7f93af5028c28");
        list.add("65e57cd895c7f93af5028c29");
        for (String s : list) {
            Item item = detailService.getDetails(s);
        }
        return BaseResult.ok();
    }

    @GetMapping("/order")
    public BaseResult<List<Order>> selectOrder(@RequestParam("user") String user){
        return orderServiceOpenFeign.getOrders(user);
    }

}
